{% extends "layouts/base.html" %}
{% load static %}
{% block title %} 工序详情 {% endblock %}

<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}

    <!-- [ Main Content ] start -->
    <section class = "pcoded-main-container">
        <div class = "pcoded-content">
            <!-- [ breadcrumb ] start -->
            <div class = "page-header">
                <div class = "page-block">
                    <div class = "row align-items-center">
                        <div class = "col-md-12">
                            <div class = "page-header-title">
                                <h5 class = "m-b-10">工序详情</h5>
                            </div>
                            <ul class = "breadcrumb">
                                <li class = "breadcrumb-item"><a href = "{% url 'index' %}"><i
                                        class = "feather icon-home"></i></a></li>
                                <li class = "breadcrumb-item"><a href = "#!">基础数据</a></li>
                                <li class = "breadcrumb-item"><a href = "#!">工序详情</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <!-- [ breadcrumb ] end -->
            <!-- [ Main Content ] start -->
            <div class = "row">

                <!-- [ stiped-table ] start -->
                <div class = "col-xl-12">
                    <div class = "card">
                        <div class = "card-header">
                            <h3>{{ process_name }}<small class = "d-block m-t-5">显示 <code>{{ process_name }}</code>
                                包含的所有子工序：</small>
                            </h3>

                            <hr>
                            <div class = "card-link text-right">
                                <a href = "{% url 'add_supprocess' process_id %}" class = "btn btn-primary"><i
                                        class = "feather mr-2 icon-plus"></i>增加子工序
                                </a>
                            </div>


                        </div>
                        <div class = "card-body table-border-style">
                            {% if error_value == 0 %}
                                <div class = "alert alert-danger text-center" role = "alert">
                                    数据库中无相关记录
                                </div>
                            {% else %}
                                <div class = "table-responsive">
                                    <table class = "table table-striped table-bordered text-center">
                                        <thead>
                                            <tr>
                                                <th>序号</th>
                                                <th>子工序名称</th>
                                                <th>所属工序</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for s in all_subprocess %}
                                                <tr>
                                                    <td>{{ forloop.counter }}</td>
                                                    <td>{{ s.name }}</td>
                                                    <td>{{ process_name }}</td>
                                                    <td>
                                                        <a href = "{% url 'update_subprocess' s.id %}"
                                                           class = "btn btn-sm btn-warning"><i
                                                                class = "feather mr-2 icon-edit-2"></i>修改</a>
                                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                                        <a href = "#" class = "btn btn-sm btn-danger del"
                                                           onclick = "javascript:del_subprocess1({{ s.id }});">
                                                            <i class = "feather mr-2 icon-trash-2"></i>删除
                                                        </a>
                                                    </td>
                                                </tr>

                                            {% endfor %}

                                        </tbody>
                                    </table>

                                </div>
                            {% endif %}
                        </div>
                        <div class = "card-footer">
                            <a href = "{% url 'process' %}" class = "btn btn-sm btn-primary">
                                <i class = "feather mr-2 icon-corner-down-left"></i>返回
                            </a>
                        </div>
                    </div>
                </div>
                <!-- [ stiped-table ] end -->

            </div>
            <!-- [ Main Content ] end -->
        </div>
    </section>
    <!-- [ Main Content ] end -->

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}
    <script src = "{% static 'assets/sweetalert/sweetalert.min.js' %}"></script>
    <script>
        function del_subprocess(sId) {
            //var $trEle = $(this).parent().parent()  //当前元素（删除按钮）的父元素（td）的父元素（tr），即这一行
            //var $delId = $trEle.children().eq(0).text() //这一行（tr）的第一个子元素的值

            $.ajaxSetup({   //获取到cookie中的csrf_token,将其添加到ajax的请求头中,防止出现错误（Forbidden."CSRF token missing or incorrect"）
                data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
            })

            $.ajax({
                url: "{% url 'del_subprocess' %}",
                type: "post",
                data: {"id": sId},
                success: function (arg) {
                    alert("此记录已经被删除成功.")
                    //swal("删除成功", "此记录已经被删除成功.", "success");
                    window.location.reload()
                    //$trEle.remove() //在页面上删除已经被删除的那行表格
                },
            });
        }

        function del_subprocess1(sId) {
            var r = confirm("你确定要删除吗？删除后将不能恢复！！！")
            if (r) {
                $.ajaxSetup({   //获取到cookie中的csrf_token,将其添加到ajax的请求头中,防止出现错误（Forbidden."CSRF token missing or incorrect"）
                    data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
                })
                $.ajax({
                    url: "{% url 'del_subprocess' %}",
                    type: "post",
                    data: {"id": sId},
                    success: function (arg) {
                        //alert("此记录已经被删除成功.")
                        //swal("删除成功", "此记录已经被删除成功.", "success");
                        window.location.reload()
                        //$trEle.remove() //在页面上删除已经被删除的那行表格
                    },
                })
            }
        }

        //使用sweetalert插件不生效，页面有闪动一下，但没有任何效果。
        function del_subprocess2(sId) {
            swal({
                    title: "你确定要删除吗？",
                    text: "删除后将无法恢复！！！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonClass: "btn-danger",
                    confirmButtonText: "删除",
                    cancelButtonClass: "btn-light",
                    cancelButtonText: "取消",
                    closeOnConfirm: false,
                },
                function () {
                    $.ajaxSetup({   //获取到cookie中的csrf_token,将其添加到ajax的请求头中,防止出现错误（Forbidden."CSRF token missing or incorrect"）
                        data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
                    })
                    //向后端发送删除请求
                    $.ajax({
                        url: "{% url 'del_subprocess' %}",
                        type: "post",
                        data: {"id": sId},
                        success: function (arg) {
                            //swal("删除成功", "此记录已经被删除成功.", "success");
                            window.location.reload()
                            //$trEle.remove() //在页面上删除已经被删除的那行表格
                        },
                    });
                }
                );
        }
    </script>
{% endblock javascripts %}
